﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FlatRedBall;
using FlatRedBall.Graphics;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Input;
using FlatRedBall.Math.Geometry;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

using BulletHellBoxes.Utilities;

namespace BulletHellBoxes.GameObjects
{
    public abstract class GameObject : PositionedObject
    {
        #region Fields
        protected string PATH;
        protected int NUM_FRAMES;
        protected float FRAME_TIME;
        protected Sprite _sprite;
        #endregion

        #region Properties
        public bool Visible
        {
            get { return _sprite.Visible; }
            set { _sprite.Visible = value; }
        }

        public bool Paused
        {
            get;
            set;
        }
        #endregion

        #region Abstract Methods
        public abstract void Activity();
        #endregion

        #region Protected Methods
        protected virtual void Initialize()
        {
            // Initialize the PositionedObject
            base.Initialize();

            // Add to the SpriteManager
            SpriteManager.AddPositionedObject(this);

            // Initialize Sprite
            AnimationChainList ani = InitializeAnimation(PATH, NUM_FRAMES, FRAME_TIME);
            _sprite = SpriteManager.AddSprite(ani);
            _sprite.AttachTo(this, false);
            _sprite.PixelScale();
        }

        protected AnimationChainList InitializeAnimation(string path, int numFrames, float frameTime)
        {
            // Loads the animation chain for when the buckle opens.
            AnimationChainList ani = new AnimationChainList();
            AnimationChain chain = new AnimationChain();

            for (int i = 1; i <= numFrames; i++)
            {
                chain.Add(new AnimationFrame(path + i, frameTime, "Global"));
            }

            ani.Add(chain);

            return ani;
        }
        #endregion

        #region Public Methods
        public virtual void Destroy()
        {
            SpriteManager.RemoveSprite(_sprite);
        }
        #endregion
    }
}
